package com.group9.handinhand.dao.model;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.apache.commons.lang.ArrayUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.group9.handinhand.service.so.CommunityTagSO;

@Entity
@Table(name = "COMMUNITY_TAG", uniqueConstraints = @UniqueConstraint(columnNames = { "TAG_ID", "COMMUNITY_ID" }))
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class CommunityTag extends AbstractBaseModel {
	
	private static final long serialVersionUID = 1L;
    
	@ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "TAG_ID", nullable = false)
    private Tag tag;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "COMMUNITY_ID", nullable = false)
	private Community community;

	public Tag getTag() {
		return tag;
	}

	public void setTag(Tag tag) {
		this.tag = tag;
	}

	public Community getCommunity() {
		return community;
	}

	public void setCommunity(Community community) {
		this.community = community;
	}

	@Override
	public String toString() {
		return "CommunityTag [tag=" + tag + ", community=" + community + "]";
	}

	public CommunityTagSO convertToServiceObject(String... ignoreProperties) {
		CommunityTagSO so = (CommunityTagSO) convert(new CommunityTagSO(),
				(String[]) ArrayUtils.addAll(ignoreProperties, new String[]{}));
		so.setCommunity(this.community.convertToServiceObject());
		so.setTag(this.tag.convertToServiceObject());
		return so;
	}

	
}
